<template>
  <div class="mobile-anniversary-list common-mobile-view">
    <anniversary-query />

    <el-empty v-if="anniversaryStore.anniversaryList.length === 0" />

    <div v-else class="anniversary-list">
      <anniversary-card v-for="(item, index) in anniversaryStore.anniversaryList"
                        :key="index" :date-item="item" />
    </div>

    <draggable-button @click="addClick"/>
  </div>
</template>

<script setup lang="ts">
import DraggableButton from '@/components/Common/DraggableButton.vue'
import AnniversaryQuery from '@/components/Anniversary/AnniversaryQuery.vue'
import AnniversaryCard from '@/components/Anniversary/AnniversaryCard.vue'
import { useAnniversaryStore } from '@/store/anniversary.ts'
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'

const anniversaryStore = useAnniversaryStore()
const router = useRouter()

onMounted(async () => {
  await anniversaryStore.queryAnniversaryList()
})

const addClick = () => {
  anniversaryStore.anniversaryApiType = 'ADD'
  anniversaryStore.currentAnniversary = anniversaryStore.getEmptyAnniversary()
  router.push({ name: 'AnniversaryDetailId', params: { id: 0 } })
}
</script>

<style lang="scss">
.mobile-anniversary-list {
  display: flex;
  flex-direction: column;
  gap: 10px;

  .anniversary-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
}
</style>
